
#include "simu.h"

Simu::Simu() {
    // register_private_parameters(EchoLen,TargetNum,FrPt,FrFs,FrNum,FrFre,FrPw,FrBw,FrType,TargetRCS1);
    // register_private_parameters(TargetRCS2,TargetRCSType1,TargetRCSType2,TargetRange1,TargetRange2,TargetVel1,TargetVel2,NoiseRcs,AddNoise,BeamAmpFilePath);
    Init();
}

Simu::~Simu() {
}


bool Simu::Init() {
    rasp_simu.SetBeamAmpFile(BeamAmpFilePath.c_str());
    rasp_simu.SetEchoLen(EchoLen);
    return true;
}



int logger_init()
{
    return 0;
}

void logger_log(const char *levelC, const char *file, int line, const char *fmt, ...)
{
    std::cout << fmt << std::endl;
}

void Simu::onCompute(buffer_table_t *input, buffer_table_t *output) {
    std::cout << "Simu::onCompute ......" << std::endl;
    int useSimuPara = 1; //GlobalParameters::shareInstance()->get_parameter_useSimuPara(
            //this);//useSimuPara 0:用Global全局参数，1： 用私有参数
    
    EchoLen = FrPt * FrFs * FrNum * sizeof(std::complex < float > );
    // 4600 * 2 * 16 * 8
    rasp_simu.SetFrPt(FrPt);
    rasp_simu.SetFrFs(FrFs);
    rasp_simu.SetEchoLen(EchoLen);
    rasp_simu.SetTargetNum(TargetNum);
    rasp_simu.SetFrPt(FrPt);
    rasp_simu.SetFrFs(FrFs);
    rasp_simu.SetFrNum(FrNum);
    rasp_simu.SetSubFrFre(SubFrFre);
    rasp_simu.SetSubFrFs(SubFrFs);
    rasp_simu.SetSubFrPt(SubFrPt);
    rasp_simu.SetSubFrPw(SubFrPw);
    rasp_simu.SetSubFrBw(SubFrBw);
    rasp_simu.SetSubFrType(SubFrType);
    rasp_simu.SetTargetRCS1(TargetRCS1);
    rasp_simu.SetTargetRCS2(TargetRCS2);
    rasp_simu.SetTargetRCSType1(TargetRCSType1);
    rasp_simu.SetTargetRCSType2(TargetRCSType2);
    rasp_simu.SetTargetRange1(TargetRange1);
    rasp_simu.SetTargetRange2(TargetRange2);
    rasp_simu.SetTargetVel1(TargetVel1);
    rasp_simu.SetTargetVel2(TargetVel2);
    rasp_simu.SetNoiseRcs(NoiseRcs);

    if (output->list[0]->len < EchoLen) {
        LOG_ERROR("The output space is not enough for simu echo!");
        return;
    }

    // output->list[0]->data: 160000个Complex，或1280000字节，共有10000 * 8 * 16个脉冲
    // 每个脉冲长为10000，共有16个脉冲，复数占8个字节
    memcpy((unsigned int *) output->list[0]->data, &FrNum, sizeof(unsigned int));
    rasp_simu.DataProcess(nullptr, 0, output->list[0]->data + sizeof(unsigned int), output->list[0]->len-1);
}
